package jp.sourceforge.akjrcp.dropsomething.actions;

import java.io.File;

import jp.sourceforge.akjrcp.akj_betas.Akj_betasPlugin;
import jp.sourceforge.akjrcp.dropsomething.DropsomethingAction;
import jp.sourceforge.akjrcp.ffmpeg.FFMpegUtils;
import jp.sourceforge.akjrcp.ffmpeg.SimpleCommandExecuter;
import jp.sourceforge.akjrcp.util.FileNameUtils;
import jp.sourceforge.akjrcp.videotools.VideoToolsSettingPage;

public class AsfbinIndexAction implements DropsomethingAction{

	public void exec(File input,File output) {
		String exe=Akj_betasPlugin.getDefault().getPluginPreferences().getString(VideoToolsSettingPage.PATH_ASFBIN);
		if(!exe.equals("")){
			String origin=output.getAbsolutePath();
			File tmp1=FileNameUtils.makeBackupFile(output, "tmp");
			boolean b=output.renameTo(tmp1);//for update..
			if(b){
				String command[]={exe,"-i",tmp1.getAbsolutePath(),"-sionly", "-y", "-o",origin};
				Akj_betasPlugin.getDefault().logPrintln(FFMpegUtils.toPrintCommand(command));
				SimpleCommandExecuter executer =new SimpleCommandExecuter(command);
				executer.setPrinter(Akj_betasPlugin.getDefault().getProcessPrinter());
				executer.execute();
				boolean d=tmp1.delete();
				if(!d){
					Akj_betasPlugin.getDefault().logPrintln("asfbin:delete tmp faild");
				}
			}else{
				Akj_betasPlugin.getDefault().logPrintln("asfbin:rename faild");
			}
			
			
		}else{
			Akj_betasPlugin.getDefault().logPrintln("asfbin.exe is not setted");
		}
	}
}
